package org.jks.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;

import org.hibernate.annotations.GenericGenerator;
import org.jks.report.model.SparePartsModel;

import com.google.gson.annotations.Expose;

@Entity
@Table(name = "SpareParts",uniqueConstraints = {@UniqueConstraint(columnNames={"Group", "DeviceType"})})
public class SpareParts {
	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@Expose
	private long Id;
	@Version
	@Column(name = "Version", unique = false, nullable = false)
	@Expose
	public Integer Version;
	@ManyToOne
	@JoinColumn(name = "[Group]", referencedColumnName = "Id", nullable = false)
	@Expose
	private Flight Group;
	@ManyToOne
	@JoinColumn(name = "DeviceType", referencedColumnName = "Id", nullable = false)
	@Expose
	private DeviceType DeviceType;
	@Expose
	private long Count;
	@Expose
	private long MinInventory;

	public long getId() {
		return Id;
	}

	public void setId(long id) {
		Id = id;
	}
	
	public Integer getVersion() {
		return Version;
	}

	public void setVersion(Integer version) {
		Version = version;
	}

	public Flight getGroup() {
		return Group;
	}

	public void setGroup(Flight group) {
		Group = group;
	}

	public DeviceType getDeviceType() {
		return DeviceType;
	}

	public void setDeviceType(DeviceType deviceType) {
		DeviceType = deviceType;
	}

	public long getCount() {
		return Count;
	}

	public void setCount(long count) {
		Count = count;
	}

	public long getMinInventory() {
		return MinInventory;
	}

	public void setMinInventory(long minInventory) {
		MinInventory = minInventory;
	}

	
	public SparePartsModel toModel(){
		SparePartsModel model = new SparePartsModel();
		model.setCount(this.Count + "");
		model.setDeviceType(this.getDeviceType().getName());
		model.setGroup(this.getGroup().getName());
		model.setId(this.Id + "");
		model.setMinInventory(this.getMinInventory() + "");
		return model;
	}
}
